using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace AssetTools
{
    public class EventCenter
    {
        public delegate void OnActionHandler(object userData);
        public Dictionary<ushort, OnActionHandler> dic = new Dictionary<ushort, OnActionHandler>();

        public void AddEventListener(ushort key, OnActionHandler handler)
        {
            dic[key] = handler;
        }

        public void RemoveEventListener(ushort key)
        {
            dic.Remove(key);
        }

        public void Dispatch(ushort key, object userData = null)
        {
            OnActionHandler handler = null;
            dic.TryGetValue(key, out handler);

            if (handler != null)
            {
                handler?.Invoke(userData);
            }
        }
    }
}